# Copyright (c) 2014-2015 The Regents of the University of California.
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject
# to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#-----------------------------------------------------------------------------
# Config to find SimVascular with cmake find_package
#-----------------------------------------------------------------------------
if(SimVascular_ALREADY_INCLUDED)
  return()
endif()
set(SimVascular_ALREADY_INCLUDED 1)

#-----------------------------------------------------------------------------
# Versioning
set(SimVascular_VERSION       "@SV_FULL_VERSION@")
set(SimVascular_MAJOR_VERSION "@SV_MAJOR_VERSION@")
set(SimVascular_MINOR_VERSION "@SV_MINOR_VERSION@")
set(SimVascular_PATCH_VERSION "@SV_PATCH_VERSION@")
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Compute the installation prefix from SimVascularConfig.cmake file
get_filename_component(SimVascular_CONFIG_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)

set(SimVascular_SOURCE_DIR "@SV_CONF_SOURCE_DIR@")
if ("${SimVascular_SOURCE_DIR}" STREQUAL "")
  set(SV_SOURCE_DIR "${SimVascular_CONFIG_DIR}")
  set(SimVascular_SOURCE_DIR "${SimVascular_CONFIG_DIR}")
  set(SimVascular_CMAKE_DIR "${SimVascular_SOURCE_DIR}/CMake")
  set(SimVascular_EXTERNALS_DIR "${SimVascular_SOURCE_DIR}/Externals")
  set(SimVascular_EXTERNALS_CMAKE_DIR "${SimVascular_SOURCE_DIR}/Externals/CMake")
else()
  set(SV_SOURCE_DIR "${SimVascular_SOURCE_DIR}")
  set(SimVascular_CMAKE_DIR "${SimVascular_SOURCE_DIR}/CMake")
  set(SimVascular_EXTERNALS_DIR "${SimVascular_SOURCE_DIR}/../Externals")
  set(SimVascular_EXTERNALS_CMAKE_DIR "${SimVascular_SOURCE_DIR}/../Externals/CMake")
endif()

set(SimVascular_BINARY_DIR "@SV_CONF_BINARY_DIR@")
if ("${SimVascular_BINARY_DIR}" STREQUAL "")
  set(SimVascular_BINARY_DIR "${SimVascular_CONFIG_DIR}/../../..")
endif()
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Paths for headers, binaries, libraries
set(SimVascular_RUNTIME_DIR "${SimVascular_BINARY_DIR}/@SV_INSTALL_RUNTIME_DIR@")
set(SimVascular_LIBRARY_DIR "${SimVascular_BINARY_DIR}/@SV_INSTALL_LIBRARY_DIR@")
set(SimVascular_INCLUDE_DIR "${SimVascular_BINARY_DIR}/@SV_INSTALL_INCLUDE_DIR@")
set(SimVascular_ARCHIVE_DIR "${SimVascular_BINARY_DIR}/@SV_INSTALL_ARCHIVE_DIR@")
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Paths for headers, binaries, libraries
set(SimVascular_C_FLAGS   "@CMAKE_C_FLAGS@")
set(SimVascular_CXX_FLAGS "@CMAKE_CXX_FLAGS@")
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Set all available libraries
set(CONF_USED_LIBS "@SV_CONF_USED_LIBS@")
set(CONF_USED_PLUGINS "@SV_CONF_USED_PLUGINS@")
set(SimVascular_LIBRARIES "")
foreach(lib ${CONF_USED_LIBS})
  list(APPEND SimVascular_LIBRARIES "${SimVascular_LIBRARY_DIR}/${lib}")
  if(WIN32)
    list(APPEND SimVascular_LIBRARIES "${SimVascular_RUNTIME_DIR}/${lib}")
  endif()
endforeach()
foreach(lib ${CONF_USED_PLUGINS})
  list(APPEND SimVascular_LIBRARIES "${SimVascular_LIBRARY_DIR}/plugins/${lib}")
  if(WIN32)
    list(APPEND SimVascular_LIBRARIES "${SimVascular_RUNTIME_DIR}/plugins/${lib}")
  endif()
endforeach()
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Set all header locations
set(CONF_INCLUDE_DIRS "@SV_CONF_INCLUDE_DIRS@")
set(SimVascular_INCLUDE_DIRS "")
if("${CONF_INCLUDE_DIRS}" STREQUAL "")
  set(SimVascular_INCLUDE_DIRS
    "${SimVascular_INCLUDE_DIR}/core"
    "${SimVascular_INCLUDE_DIR}/thirdparty/solverio"
    "${SimVascular_INCLUDE_DIR}/thirdparty/tetgen"
    "${SimVascular_INCLUDE_DIR}/thirdparty/vmtk"
    "${SimVascular_INCLUDE_DIR}/thirdparty/zlib")
else()
  foreach(dir ${CONF_INCLUDE_DIRS})
    list(APPEND SimVascular_INCLUDE_DIRS "${SimVascular_SOURCE_DIR}/${dir}")
    list(APPEND SimVascular_INCLUDE_DIRS "${SimVascular_BINARY_DIR}/${dir}")
  endforeach()
endif()
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Now for externals
set(SimVascular_USE_EXTERNALS_FILE "${SimVascular_CMAKE_DIR}/SimVascularUseExternals.cmake")
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# For install
if(NOT DEFINED OUTBIN_DIR OR NOT DEFINED OUTLIB_DIR)
  set(OUTBIN_DIR "${CMAKE_BINARY_DIR}/bin")
  set(OUTLIB_DIR ${CMAKE_BINARY_DIR}/lib)
endif()

if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OUTBIN_DIR}")
endif()

if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OUTLIB_DIR}")
endif()

if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${OUTLIB_DIR}")
endif()

mark_as_advanced(CMAKE_RUNTIME_OUTPUT_DIRECTORY
  CMAKE_LIBRARY_OUTPUT_DIRECTORY
  CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
#-----------------------------------------------------------------------------
